package com.wilschrader.demarche.models;

import com.wilschrader.demarche.DamageModel;
import com.wilschrader.demarche.Unit;

/**
 * Default Damage Model
 * 1) Units that sustain damage and AREN'T damaged should absorb hits first.
 * 2) Units that are carrying other units should be damaged last.
 * 3) Units that have a higher combat value should be damaged last.
 * 4) Units that have a higher number of shots-per-round should be damaged last.
 * 5) Units that cost more should be damaged last.
 * 
 * @author Wil Schrader
 * @modifications
 * 	08172011	Initial revision.
 * 
 */
public class DefaultDamageModel implements DamageModel {

	@Override
	public int compare(Unit a, Unit b) {
		if (a.sustainsDamage() && b.sustainsDamage()) {
			if (a.isDamaged() && !b.isDamaged()) {
				return 1;
			} else if (!a.isDamaged() && b.isDamaged()) {
				return -1;
			}
		} else if (a.sustainsDamage() && !b.sustainsDamage()) {
			if (!a.isDamaged()) {
				return -1;
			}
		} else if (!a.sustainsDamage() && b.sustainsDamage()) {
			if (!b.isDamaged()) {
				return 1;
			}
		}
		
		if (a.count() > b.count()) {
			return 1;
		} else if (a.count() < b.count()) {
			return -1;
		}
		
		if (a.getCombatValue() > b.getCombatValue()) {
			return 1;
		} else if (a.getShotCount() > b.getShotCount()) {
			return 1;
		}
		
		if (a.getCombatValue() < b.getCombatValue()) {
			return -1;
		} else if (a.getShotCount() < b.getShotCount()) {
			return -1;
		}
		
		return a.getCost() - b.getCost();
	}

}
